package com.hongkuncheng.cms.config;

import com.hongkuncheng.cms.freemaker.admin.CheckPermissionMethod;
import com.hongkuncheng.cms.freemaker.article.GetDetailLinkMethod;
import com.hongkuncheng.cms.freemaker.article.GetPageContentsMethod;
import com.hongkuncheng.cms.freemaker.string.ClearStringBrMethod;
import com.hongkuncheng.cms.freemaker.string.EscapeHtmlMethod;
import com.hongkuncheng.cms.freemaker.string.SubstringMethod;
import com.hongkuncheng.cms.freemaker.string.UrlEncodeMethod;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
public class FreemarkerConfig {

    @Resource
    private freemarker.template.Configuration configuration;

    @Resource
    public UrlEncodeMethod urlEncode;
    @Resource
    public EscapeHtmlMethod escapeHtml;
    @Resource
    public SubstringMethod substring;
    @Resource
    public ClearStringBrMethod clearStringBr;
    @Resource
    public CheckPermissionMethod checkPermission;
    @Resource
    public GetDetailLinkMethod getDetailLink;
    @Resource
    public GetPageContentsMethod getPageContents;

    @PostConstruct
    public void setConfigure() throws Exception {
        configuration.setSharedVariable("urlEncode", urlEncode);
        configuration.setSharedVariable("escapeHtml", escapeHtml);
        configuration.setSharedVariable("substring", substring);
        configuration.setSharedVariable("clearStringBr", clearStringBr);
        configuration.setSharedVariable("checkPermission", checkPermission);
        configuration.setSharedVariable("getDetailLink", getDetailLink);
        configuration.setSharedVariable("getPageContents", getPageContents);
    }
}
